Skip to content

NAS-138384 / 26.04 / Properly handle oneOf schema case#124

Merged
Qubad786 merged 1 commit into
masterfrom
mrehan/fix-pydantic-model-discriminator
Nov 4, 2025
Merged

NAS-138384 / 26.04 / Properly handle oneOf schema case#124
Qubad786 merged 1 commit into
masterfrom
mrehan/fix-pydantic-model-discriminator

Conversation

@Qubad786

@Qubad786 Qubad786 commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

Problem

We had midcli failing with the following pydantic model

class PoolDatasetCreateArgs(BaseModel):
    data: PoolDatasetCreateFilesystem | PoolDatasetCreateVolume = Field(discriminator='type')
    """Configuration data for creating a new ZFS dataset."""

Reason was that the schema generated for this uses oneOf and we ran into key error because of this as this was not handled.
Example schema:

{
  "discriminator": {
    "mapping": {
      "FILESYSTEM": "#/$defs/FilesystemType",
      "VOLUME": "#/$defs/VolumeType"
    },
    "propertyName": "type"
  },
  "oneOf": [
    {
      "properties": {
        "type": {
          "const": "FILESYSTEM",
          "default": "FILESYSTEM",
          "title": "type",
          "type": "string",
          "_name_": "type",
          "_required_": false
        },
        "name": {
          "title": "name",
          "type": "string",
          "_name_": "name",
          "_required_": true
        },
        "recordsize": {
          "default": "128K",
          "title": "recordsize",
          "type": "string",
          "_name_": "recordsize",
          "_required_": false
        }
      },
      "required": [
        "name"
      ],
      "title": "FilesystemType",
      "type": "object",
      "_attrs_order_": [
        "type",
        "name",
        "recordsize"
      ]
    },
    {
      "properties": {
        "type": {
          "const": "VOLUME",
          "default": "VOLUME",
          "title": "type",
          "type": "string",
          "_name_": "type",
          "_required_": false
        },
        "name": {
          "title": "name",
          "type": "string",
          "_name_": "name",
          "_required_": true
        },
        "volsize": {
          "title": "volsize",
          "type": "integer",
          "_name_": "volsize",
          "_required_": true
        }
      },
      "required": [
        "name",
        "volsize"
      ],
      "title": "VolumeType",
      "type": "object",
      "_attrs_order_": [
        "type",
        "name",
        "volsize"
      ]
    }
  ],
  "title": "data",
  "_name_": "data",
  "_required_": true
}

Solution

Properly handle oneOf in midcli so that it gets parsed in the correct way similar to how anyOf works.

@yocalebo yocalebo requested a review from themylogin November 4, 2025 18:39
@Qubad786 Qubad786 added the jira label Nov 4, 2025
@bugclerk bugclerk changed the title Properly handle oneOf schema case NAS-138384 / 26.04 / Properly handle oneOf schema case Nov 4, 2025
@bugclerk

bugclerk commented Nov 4, 2025

Copy link
Copy Markdown

@Qubad786 Qubad786 merged commit 4ebf730 into master Nov 4, 2025
2 checks passed
@bugclerk

bugclerk commented Nov 4, 2025

Copy link
Copy Markdown

This PR has been merged and conversations have been locked.
If you would like to discuss more about this issue please use our forums or raise a Jira ticket.

@truenas truenas locked as resolved and limited conversation to collaborators Nov 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants